// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

// 1.引入element-ui包
import elementUI from 'element-ui'
// 2.引入element-ui的样式表
import 'element-ui/lib/theme-chalk/index.css'
// 4.引入common.css通用样式
import './assets/css/common.css'
// 5.引入第三方图标库
import './assets/fonts/iconfont.css'
// 引入axios
import axios from 'axios'
// 引入vue-table-with-tree-grid
import treeTable from 'vue-table-with-tree-grid'
//导入vue-quill-editor（富文本编辑器）
import VueQuillEditor from 'vue-quill-editor'
//导入vue-quill-editor的样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

Vue.config.productionTip = false
// 3.使用element-ui
Vue.use(elementUI)
// 全局引入treeTable组件
Vue.component('tree-table',treeTable)
// 全局注册vue-quill-editor
Vue.use(VueQuillEditor)

// 全局基础设置
axios.defaults.baseURL="http://127.0.0.1:8888/api/private/v1/"

// 请求拦截器
axios.interceptors.request.use(config=>{
  config.headers.Authorization = window.sessionStorage.getItem("token")
  return config
})
// 响应拦截器
axios.interceptors.response.use(info=>{
  return info.data
})

// 全局绑定axios
Vue.prototype.$axios=axios

// 全局日期过滤器
Vue.filter("getTime", function (val, a) {
  function dateFormat(date, format) {
      if (typeof date === "string") {
          var mts = date.match(/(\/Date\((\d+)\)\/)/);
          if (mts && mts.length >= 3) {
              date = parseInt(mts[2]);
          }
      }
      date = new Date(date);
      if (!date || date.toUTCString() == "Invalid Date") {
          return "";
      }
      var map = {
          "M": date.getMonth() + 1, //月份 
          "d": date.getDate(), //日 
          "h": date.getHours(), //小时 
          "m": date.getMinutes(), //分 
          "s": date.getSeconds(), //秒 
          "q": Math.floor((date.getMonth() + 3) / 3), //季度 
          "S": date.getMilliseconds() //毫秒 
      };

      format = format.replace(/([yMdhmsqS])+/g, function (all, t) {
          var v = map[t];
          if (v !== undefined) {
              if (all.length > 1) {
                  v = '0' + v;
                  v = v.substr(v.length - 2);
              }
              return v;
          } else if (t === 'y') {
              return (date.getFullYear() + '').substr(4 - all.length);
          }
          return all;
      });
      return format;
  }
  return dateFormat(val,a);
})


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
